package org.backend.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiResponse<T> {
    private int code;
    private T data;
    private String msg;

    // 成功响应
    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(200, data, "操作成功");
    }

    // 错误响应
    public static <T> ApiResponse<T> error(String msg) {
        return new ApiResponse<>(400, null, msg);  // 可以根据需要定制错误码
    }

    // 可自定义的错误响应（带状态码）
    public static <T> ApiResponse<T> error(int code, String msg) {
        return new ApiResponse<>(code, null, msg);
    }
}
